package com.rongcheng.fortestlist.EXELFrameworkDemo.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.TextView;

import com.rongcheng.fortestlist.EXELFrameworkDemo.model.QANode;
import com.rongcheng.fortestlist.EXELFrameworkDemo.utils.FragmentCreator;
import com.rongcheng.fortestlist.R;

/**
 * @author frc
 *         created at 17-1-4.
 */

public abstract class QABaseFragment extends Fragment {

    public QANode node;
    private static String KEY_NODE = "KEY NODE";

    public static QABaseFragment getFragment(QANode node) {
        QABaseFragment f = FragmentCreator.getInstance().createFragment(node);
        f.node = node;
        return f;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(null);
        if (savedInstanceState != null) {
            node = (QANode) savedInstanceState.getSerializable(KEY_NODE);
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putSerializable(KEY_NODE, node);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    protected void setQuestionNumber(View view) {
        TextView textView = (TextView) view.findViewById(R.id.tv_question_number);
        textView.setText(node.getPrefixNumber() + "/" + node.getPostfixNumber());
    }
}
